#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct _candidate
{
    char name[30];
    int voteCount;
}Candidate;

void disCandidateRes(Candidate* c,int n,int vCount)
{
    for(int i = 0 ; i < n; i++)
    {
        printf("Name: %10s  VoteCount: %2d \n",c[i].name,c[i].voteCount);
    }
    printf("弃权的人数：%d\n",vCount);
    int idx =0;
    for(int i = 0; i<n; i++)
    {
        if(c[i].voteCount > c[idx].voteCount)
            idx = i;
    }
    printf("恭喜 %s 获得了本次选举\n",c[idx].name);
}
int main()
{
    Candidate can[3] =
    {
        {"zhangsan",0},
        {"lisi",0},
        {"wangwu",0}
    };
//    disCandidateRes(can,3);

    char buf[1024];
    int vCount =0;
    // 10 个人，投 10 次。
    for(int i = 0; i <10; i ++)
    {
        printf("pls intput your like:");
        scanf("%s",buf);
        int nameFlag =1;
        for(int i=0; i<3; i++)
        {

            if(!strcmp(buf,can[i].name))
            {
                can[i].voteCount++;
                nameFlag =0;
            }
        }
        if(nameFlag != 0)
        {
            vCount++;
        }
    }

    disCandidateRes(can,3,vCount);

    return 0;
}
